//===============================================================================
// Microsoft patterns & practices Enterprise Library Contribution
// Policy Injection Application Block
//===============================================================================

using System.Collections.Generic;
using System.Configuration;
using System.ComponentModel;
using System.Windows.Forms;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ContainerModel;
using Microsoft.Practices.EnterpriseLibrary.PolicyInjection.Configuration;
using Microsoft.Practices.Unity;
using Microsoft.Practices.Unity.InterceptionExtension;

namespace EntLibContrib.PolicyInjection.CallHandlers.Configuration
{
	/// <summary>
	/// Cursor Call Handler Data
	/// </summary>
	public class CursorCallHandlerData : CallHandlerData
	{
		#region Constants
		private const string CursorPropertyName = "cursor";
		#endregion

		#region Properties
		/// <summary>
		/// The cursor as available on the Cursors class.
		/// </summary>
		/// <value>The "cursor" attribute in configuration</value>
		[ConfigurationProperty(CursorPropertyName, IsRequired = true, DefaultValue = "Default")]
		[TypeConverter(typeof(CursorConverter))]
		public Cursor Cursor
		{
			get { return (Cursor)base[CursorPropertyName]; }
			set { base[CursorPropertyName] = value; }
		}
		#endregion

		#region Construction
		/// <summary>
		/// Construct a new <see cref="CursorCallHandlerData"/>.
		/// </summary>
		public CursorCallHandlerData()
		{
		}

		/// <summary>
		/// Construct a new <see cref="CursorCallHandlerData"/>.
		/// </summary>
		/// <param name="handlerName">Name of the handler.</param>
		public CursorCallHandlerData(string handlerName)
			: base(handlerName, typeof(CursorCallHandler))
		{
		}

		/// <summary>
		/// Construct a new <see cref="CursorCallHandlerData"/>.
		/// </summary>
		/// <param name="handlerName">Name of the handler.</param>
		/// <param name="handlerOrder">The handler order.</param>
		public CursorCallHandlerData(string handlerName, int handlerOrder)
			: base(handlerName, typeof(CursorCallHandler))
		{
			Order = handlerOrder;
		}
		#endregion

		#region Public Methods
		/// <summary>
		/// Get the set of <see cref="TypeRegistration"/> objects needed to
		/// register the call handler represented by this config element and its associated objects.
		/// </summary>
		/// <param name="nameSuffix">A suffix for the names in the generated type registration objects.</param>
		/// <returns>The set of <see cref="TypeRegistration"/> objects.</returns>
		public override IEnumerable<TypeRegistration> GetRegistrations(string nameSuffix)
		{
			yield return
				new TypeRegistration<ICallHandler>(
					() => new CursorCallHandler(Cursor))
				{
					Name = this.Name + nameSuffix,
					Lifetime = TypeRegistrationLifetime.Transient
				};
		}

		#endregion
	}
}
